/*************************************************************************\
*                  Copyright (C) Michael Kerrisk, 2020.                   *
*                                                                         *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU General Public License as published by the   *
* Free Software Foundation, either version 3 or (at your option) any      *
* later version. This program is distributed without any warranty.  See   *
* the file COPYING.gpl-v3 for details.                                    *
\*************************************************************************/

/* Listing 27-5 */

/* t_execl.c

   Demonstrate the use of execl() to execute printenv(1).

   New program inherits env-vars from the old program.
*/
#include <stdlib.h>
#include "tlpi_hdr.h"

int
main(int argc, char *argv[])
{
	printf("Initial value of USER: %s\n", getenv("USER"));

	// set 'USER' to new value.
	
	if (putenv("USER=britta") != 0)
		errExit("putenv");

	/* exec printenv to display the USER and SHELL environment vars */

	execl("/usr/bin/printenv", "printenv", "USER", "SHELL", (char *) NULL);

	errExit("execl");           /* If we get here, something went wrong */
}
